/**
 * @author 		chenc
 * @version 	1.0
 * @date 		2016.1.11
 *
 * @file 		sct/rtspserver/rtspserverinterface.h
 * @brief 		rtsp server interface
 *
 * CRTSPServerInterface
 */

#ifndef SCT_RTSPSERVER_RTSPSERVERINTERFACE_H
#define SCT_RTSPSERVER_RTSPSERVERINTERFACE_H

#include <stdint.h>
#include <stddef.h>

namespace sct
{
class CServerMediaSession;
class CServerMediaSubsession;

class CRTSPServerInterface
{
public:
	enum Type
	{
		H264 = 1,
		AAC,
		AMR,
		TS,
	};
	class CStreamInfo
	{
	public:
		Type type;

		int profile;
		int frequency;
		int channel_config;
	};

public:
	/**
	 * destructor issues destroying the object
	 */
	virtual ~CRTSPServerInterface(){}

	/**
	 * create a object
	 *
	 * thread unsafe
	 *
	 * @param name should be "rtspserver"
	 * @param port the rtsp server used port
	 */
	static CRTSPServerInterface* create(const char * name, const int port = 554);

	/*
	 * create a session
	 *
	 * @param path this arg will append to the base url. for example
	 * "rtsp://127.0.0.1:8559/path". the path must leading by '/'
	 */
	virtual CServerMediaSession* createServerMediaSession(
			const char* path){return NULL;}

	virtual CServerMediaSubsession* createServerMediaSubsession(
			CServerMediaSession* session, const CStreamInfo & info){return NULL;}

	/**
	 * init a object
	 *
	 * after you call create(), you should call this to init a object.
	 * @see getUrl()
	 */
	virtual void init() {}

	/**
	 * get the server Url
	 *
	 * the url is composed by base path and the user path(setted by init). you must call it after the
	 * init(). \n sometimes it will return rtsp://0.0.0.0:8559/path address, because the network is no ready yet.
	 * you should call it until return the right format to you.
	 */
	virtual const char* getUrl(CServerMediaSession* session) {return NULL;}
	/**
	 * put the data for sending
	 *
	 * put the source data for sending.\n
	 * @param p point to the data address
	 * @param len the size of data
	 * @param pts is the present time of the data. in microsecond.
	 */
	virtual void putMediaData(CServerMediaSubsession* subsession,
			const void*p, const int len, const int64_t pts){}
protected:
	/**
	 * the empty constructor
	 */
	CRTSPServerInterface(){}
};

}

#endif
